package com.hq.talk.view.ui;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.hq.lib_comview.common.utils.ImageUtils;
import com.hq.lib_comview.common.utils.StringUtils;
import com.hq.lib_comview.view.baseadp.CommonAdapter;
import com.hq.lib_comview.view.baseadp.ViewHolder;
import com.hq.lib_comview.view.selview.MyListView;
import com.hq.talk.R;
import com.hq.talk.common.Session;
import com.hq.talk.model.CommItemModel;
import com.hq.talk.view.base.BaseCommAty;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 描述 ：个人空间
 * 作者 ：hq
 * 时间 ：2017/8/9 21:03
 */
public class MySpaceAty extends BaseCommAty implements AdapterView.OnItemClickListener {

    //头像
    ImageView mImgUserHead;
    //昵称
    TextView mTxtUserName;
    //性别
    ImageView mImgSex;
    //签名
    TextView mTxtSign;

    @BindView(R.id.id_space_listv)
    MyListView myListView;
    CommonAdapter<CommItemModel> mMineAdp;
    private List<CommItemModel> mItems = new ArrayList<CommItemModel>();

    @Nullable
    @Override
    public View loadView(LayoutInflater inflater, View childView) {
        return super.loadView(inflater, inflater.inflate(R.layout.aty_my_space, null, false));
    }

    @Override
    public boolean hasDataInPage() {
        return true;
    }

    /**
     * 初始化头布局
     */
    private void initHeadView() {
        View mHeadView = LayoutInflater.from(aty).inflate(R.layout.layout_mine_info, null);
        mImgUserHead = (ImageView) mHeadView.findViewById(R.id.id_user_head_img);
        mTxtUserName = (TextView) mHeadView.findViewById(R.id.id_user_name_txt);
        mImgSex = (ImageView) mHeadView.findViewById(R.id.id_user_sex_img);
        mTxtSign = (TextView) mHeadView.findViewById(R.id.id_user_sign_txt);
        myListView.addHeaderView(mHeadView);

        setUserInfo();
        mHeadView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isLogin(false)) {

                }
            }
        });
    }

    /**
     * 设置用户信息
     */
    public void setUserInfo() {
        ImageUtils.showCircleImg(aty, Session.getUserHead(), R.drawable.ic_default_user_head, R.drawable.ic_default_user_head, mImgUserHead);
        mTxtUserName.setText(Session.getUserName());
        mImgSex.setVisibility(View.VISIBLE);
        if (TextUtils.equals("1", Session.getUserSex())) {
            //男
//            mImgSex.setBackgroundResource(R.drawable.);
        } else {
            //女
//            mImgSex.setBackgroundResource(R.drawable.);
        }
        if (StringUtils.isEmpty(Session.getUserSign())) {
            mTxtSign.setVisibility(View.GONE);
        } else {
            mTxtSign.setVisibility(View.VISIBLE);
            mTxtSign.setText(Session.getUserSign());
        }
    }

    @Override
    public void initView() {
        setTitleText(getString(R.string.my_info), null);
        initHeadView();
        CommItemModel model = new CommItemModel(R.drawable.ic_my_exchange, getString(R.string.my_exchange), "");
        CommItemModel model1 = new CommItemModel(R.drawable.ic_my_expo, getString(R.string.my_expo), "");
        CommItemModel model2 = new CommItemModel(R.drawable.ic_my_work, getString(R.string.my_work), "");
        CommItemModel model3 = new CommItemModel(R.drawable.ic_my_address, getString(R.string.my_address), "");
        mItems.add(model);
        mItems.add(model1);
        mItems.add(model2);
        mItems.add(model3);
    }

    @Override
    public void initData() {
        mMineAdp = new CommonAdapter<CommItemModel>(aty, mItems, R.layout.item_mine) {
            @Override
            public void convert(ViewHolder helper, CommItemModel item) {
                if (null != item) {
                    helper.setBackgroundResource(R.id.id_mine_icon_img, item.getDrawable());
                    helper.setText(R.id.id_mine_title_txt, item.getName());
                    if (StringUtils.isEmpty(item.getmDesc())) {
                        helper.setText(R.id.id_mine_desc_txt, "");
                    } else {
                        helper.setText(R.id.id_mine_desc_txt, item.getmDesc());
                    }
                    if (item.isDivider()) {
                        helper.getView(R.id.id_line_1).setVisibility(View.GONE);
                        helper.getView(R.id.id_line_2).setVisibility(View.VISIBLE);
                    } else {
                        helper.getView(R.id.id_line_1).setVisibility(View.VISIBLE);
                        helper.getView(R.id.id_line_2).setVisibility(View.GONE);
                    }
                }
            }
        };
        myListView.setAdapter(mMineAdp);
        myListView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case 1:
                //交易记录
                if (isLogin(true)) {

                }
                break;
            case 2:
                //我的展厅
                if (isLogin(true)) {

                }
                break;
            case 3:
                //工作技能
                if (isLogin(true)) {
                    showActivity(aty, MyWorkAty.class);
                }
                break;
            case 4:
                //地址
                if (isLogin(true)) {

                }
                break;
        }
    }
}
